﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WLMCoreLibrary;
using MiWebSite_Core;
using System.Xml;

namespace MWS_Main
{
    public partial class AuthorizeTwitter : System.Web.UI.Page
    {
        protected void Page_Load( object sender, EventArgs e )
        {
            //WebSiteMainConfiguration config = WebSiteMainConfiguration.GetConfig();
            //List<ParametroTransformacionXML> parametros = new List<ParametroTransformacionXML>();
            //if (Request.QueryString["xml"] != null)
            //{
            dbConnector ConexionDB = new dbConnector();
            //    MiWebSitePage pagina = new MiWebSitePage(conexion);
            //    pagina.DomainName = CurrentDomain.DomainName;
            if ( CurrentUser.IdUsuario != 0 )
            {
                if ( Request["oauth_token"] == null )
                {
                    Twitter tw = new Twitter();
                    string redireccion = tw.RequestAuthorization( new MiWebSiteDomain( CurrentDomain.IdentificadorDominio, ref ConexionDB ) );
                    Response.Redirect( redireccion );
                }
                else
                {
                    XmlDocument xmlModulos = new XmlDocument();
                    //pagina.Contenido = xmlModulos.CreateElement( "Portada" );
                    Twitter tw = new Twitter();
                    string usuarioTwitter= tw.AutorizarTwit( Request["oauth_token"], Request["oauth_verifier"], new MiWebSiteDomain( CurrentDomain.DomainName, ref ConexionDB ) );
                    Response.Write( "Twitter Correctamente autorizado para usuario \"" + usuarioTwitter + "\"" );

                }

            }
            ConexionDB.CloseConnection();
            CurrentDomain.Refresh();
            //}
            //else
            //{
            //    string HTMLPagina = WLMFunctions.TransformXML(config.Settings["siteURL"].value + "?xml=true", config.Settings["siteURL"].value + config.Settings["skinPath"].value + "index.xsl", parametros);
            //    Response.Write(HTMLPagina);
            //}
        }
    }
}